home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK1.toast / Development Kits (Disc 1) / Interfaces&Libraries / Universal / Interfaces / CIncludes / MixedMode.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-12  |  25.4 KB  |  692 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        MixedMode.h
  3.  
  4.      Contains:    Mixed Mode Manager Interfaces.
  5.  
  6.      Version:    Technology:    System 7.5
  7.                  Release:    Universal Interfaces 3.0.1
  8.  
  9.      Copyright:    © 1992-1997 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:        Please include the the file and version information (from above) with
  12.                  the problem description.  Developers belonging to one of the Apple
  13.                  developer programs can submit bug reports to:
  14.  
  15.                      devsupport@apple.com
  16.  
  17. */
  18. #ifndef __MIXEDMODE__
  19. #define __MIXEDMODE__
  20.  
  21. #ifndef __TYPES__
  22. #include <Types.h>
  23. #endif
  24.  
  25.  
  26.  
  27. #if PRAGMA_ONCE
  28. #pragma once
  29. #endif
  30.  
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34.  
  35. #if PRAGMA_IMPORT
  36. #pragma import on
  37. #endif
  38.  
  39. #if PRAGMA_STRUCT_ALIGN
  40.     #pragma options align=mac68k
  41. #elif PRAGMA_STRUCT_PACKPUSH
  42.     #pragma pack(push, 2)
  43. #elif PRAGMA_STRUCT_PACK
  44.     #pragma pack(2)
  45. #endif
  46.  
  47. /* Mixed Mode constants */
  48. /* Current Routine Descriptor Version */
  49.  
  50. enum {
  51.     kRoutineDescriptorVersion    = 7
  52. };
  53.  
  54. /* MixedModeMagic Magic Cookie/Trap number */
  55.  
  56. enum {
  57.     _MixedModeMagic                = 0xAAFE
  58. };
  59.  
  60. /* MixedModeState Version for CFM68K Mixed Mode */
  61.  
  62. enum {
  63.     kCurrentMixedModeStateRecord = 1
  64. };
  65.  
  66. /* Calling Conventions */
  67. typedef unsigned short                     CallingConventionType;
  68.  
  69. enum {
  70.     kPascalStackBased            = 0,
  71.     kCStackBased                = 1,
  72.     kRegisterBased                = 2,
  73.     kD0DispatchedPascalStackBased = 8,
  74.     kD1DispatchedPascalStackBased = 12,
  75.     kD0DispatchedCStackBased    = 9,
  76.     kStackDispatchedPascalStackBased = 14,
  77.     kThinkCStackBased            = 5
  78. };
  79.  
  80. /* ISA Types */
  81. typedef SInt8                             ISAType;
  82.  
  83. enum {
  84.     kM68kISA                    = 0,
  85.     kPowerPCISA                    = 1
  86. };
  87.  
  88. /* RTA Types */
  89. typedef SInt8                             RTAType;
  90.  
  91. enum {
  92.     kOld68kRTA                    = 0 << 4,
  93.     kPowerPCRTA                    = 0 << 4,
  94.     kCFM68kRTA                    = 1 << 4
  95. };
  96.  
  97.  
  98. #if TARGET_CPU_PPC
  99.     #define        GetCurrentISA()        ((ISAType) kPowerPCISA)
  100.     #define        GetCurrentRTA()        ((RTAType) kPowerPCRTA)
  101. #elif TARGET_CPU_68K
  102.     #define        GetCurrentISA()        ((ISAType) kM68kISA)
  103.     #if TARGET_RT_MAC_CFM
  104.         #define    GetCurrentRTA()        ((RTAType) kCFM68kRTA)
  105.     #else
  106.         #define    GetCurrentRTA()        ((RTAType) kOld68kRTA)
  107.     #endif
  108. #endif
  109. #define        GetCurrentArchitecture()    (GetCurrentISA() | GetCurrentRTA())
  110.  
  111. /* Constants for specifing 68k registers */
  112.  
  113. enum {
  114.     kRegisterD0                    = 0,
  115.     kRegisterD1                    = 1,
  116.     kRegisterD2                    = 2,
  117.     kRegisterD3                    = 3,
  118.     kRegisterD4                    = 8,
  119.     kRegisterD5                    = 9,
  120.     kRegisterD6                    = 10,
  121.     kRegisterD7                    = 11,
  122.     kRegisterA0                    = 4,
  123.     kRegisterA1                    = 5,
  124.     kRegisterA2                    = 6,
  125.     kRegisterA3                    = 7,
  126.     kRegisterA4                    = 12,
  127.     kRegisterA5                    = 13,
  128.     kRegisterA6                    = 14,                            /* A7 is the same as the PowerPC SP */
  129.     kCCRegisterCBit                = 16,
  130.     kCCRegisterVBit                = 17,
  131.     kCCRegisterZBit                = 18,
  132.     kCCRegisterNBit                = 19,
  133.     kCCRegisterXBit                = 20
  134. };
  135.  
  136. typedef unsigned short                     registerSelectorType;
  137. /* SizeCodes we use everywhere */
  138.  
  139. enum {
  140.     kNoByteCode                    = 0,
  141.     kOneByteCode                = 1,
  142.     kTwoByteCode                = 2,
  143.     kFourByteCode                = 3
  144. };
  145.  
  146. /* Mixed Mode Routine Records */
  147. typedef unsigned long                     ProcInfoType;
  148. /* Routine Flag Bits */
  149. typedef unsigned short                     RoutineFlagsType;
  150.  
  151. enum {
  152.     kProcDescriptorIsAbsolute    = 0x00,
  153.     kProcDescriptorIsRelative    = 0x01
  154. };
  155.  
  156.  
  157. enum {
  158.     kFragmentIsPrepared            = 0x00,
  159.     kFragmentNeedsPreparing        = 0x02
  160. };
  161.  
  162.  
  163. enum {
  164.     kUseCurrentISA                = 0x00,
  165.     kUseNativeISA                = 0x04
  166. };
  167.  
  168.  
  169. enum {
  170.     kPassSelector                = 0x00,
  171.     kDontPassSelector            = 0x08
  172. };
  173.  
  174.  
  175. enum {
  176.     kRoutineIsNotDispatchedDefaultRoutine = 0x00,
  177.     kRoutineIsDispatchedDefaultRoutine = 0x10
  178. };
  179.  
  180.  
  181. enum {
  182.     kProcDescriptorIsProcPtr    = 0x00,
  183.     kProcDescriptorIsIndex        = 0x20
  184. };
  185.  
  186. struct RoutineRecord {
  187.     ProcInfoType                     procInfo;                    /* calling conventions */
  188.     SInt8                             reserved1;                    /* Must be 0 */
  189.     ISAType                         ISA;                        /* Instruction Set Architecture */
  190.     RoutineFlagsType                 routineFlags;                /* Flags for each routine */
  191.     ProcPtr                         procDescriptor;                /* Where is the thing we’re calling? */
  192.     UInt32                             reserved2;                    /* Must be 0 */
  193.     UInt32                             selector;                    /* For dispatched routines, the selector */
  194. };
  195. typedef struct RoutineRecord RoutineRecord;
  196.  
  197. typedef RoutineRecord *                    RoutineRecordPtr;
  198. typedef RoutineRecordPtr *                RoutineRecordHandle;
  199. /* Mixed Mode Routine Descriptors */
  200. /* Definitions of the Routine Descriptor Flag Bits */
  201. typedef UInt8                             RDFlagsType;
  202.  
  203. enum {
  204.     kSelectorsAreNotIndexable    = 0x00,
  205.     kSelectorsAreIndexable        = 0x01
  206. };
  207.  
  208. /* Routine Descriptor Structure */
  209. struct RoutineDescriptor {
  210.     UInt16                             goMixedModeTrap;            /* Our A-Trap */
  211.     SInt8                             version;                    /* Current Routine Descriptor version */
  212.     RDFlagsType                     routineDescriptorFlags;        /* Routine Descriptor Flags */
  213.     UInt32                             reserved1;                    /* Unused, must be zero */
  214.     UInt8                             reserved2;                    /* Unused, must be zero */
  215.     UInt8                             selectorInfo;                /* If a dispatched routine, calling convention, else 0 */
  216.     UInt16                             routineCount;                /* Number of routines in this RD */
  217.     RoutineRecord                     routineRecords[1];            /* The individual routines */
  218. };
  219. typedef struct RoutineDescriptor RoutineDescriptor;
  220.  
  221. typedef RoutineDescriptor *                RoutineDescriptorPtr;
  222. typedef RoutineDescriptorPtr *            RoutineDescriptorHandle;
  223. /* 68K MixedModeStateRecord */
  224. struct MixedModeStateRecord {
  225.     UInt32                             state1;
  226.     UInt32                             state2;
  227.     UInt32                             state3;
  228.     UInt32                             state4;
  229. };
  230. typedef struct MixedModeStateRecord MixedModeStateRecord;
  231.  
  232. /* Macros for building static Routine Descriptors */
  233.  
  234. /* A macro which creates a static instance of a non-dispatched routine descriptor */
  235. #define BUILD_ROUTINE_DESCRIPTOR(procInfo, procedure)                                 \
  236.     {                                                                                \
  237.         _MixedModeMagic,                            /* Mixed Mode A-Trap */         \
  238.         kRoutineDescriptorVersion,                    /* version */                    \
  239.         kSelectorsAreNotIndexable,                    /* RD Flags - not dispatched */    \
  240.         0,                                            /* reserved 1 */                \
  241.         0,                                            /* reserved 2 */                \
  242.         0,                                            /* selector info */                \
  243.         0,                                            /* number of routines */        \
  244.         {                                            /* It’s an array */                \
  245.             {                                        /* It’s a struct */                \
  246.                 (procInfo),                            /* the ProcInfo */                \
  247.                 0,                                    /* reserved */                    \
  248.                 GetCurrentArchitecture(),             /* ISA and RTA */                \
  249.                 kProcDescriptorIsAbsolute |            /* Flags - it’s absolute addr */\
  250.                 kFragmentIsPrepared |                /* It’s prepared */                \
  251.                 kUseNativeISA,                        /* Always use native ISA */        \
  252.                 (ProcPtr)(procedure),                /* the procedure */                \
  253.                 0,                                    /* reserved */                    \
  254.                 0                                    /* Not dispatched */            \
  255.             }                                                                        \
  256.         }                                                                            \
  257.     }
  258.  
  259. /* a macro which creates a static instance of a fat routine descriptor */
  260. #define BUILD_FAT_ROUTINE_DESCRIPTOR(m68kProcInfo, m68kProcPtr, powerPCProcInfo, powerPCProcPtr)  \
  261.     {                                                                                \
  262.         _MixedModeMagic,                            /* Mixed Mode A-Trap */         \
  263.         kRoutineDescriptorVersion,                    /* version */                    \
  264.         kSelectorsAreNotIndexable,                    /* RD Flags - not dispatched */    \
  265.         0,                                            /* reserved */                    \
  266.         0,                                            /* reserved */                    \
  267.         0,                                            /* reserved */                    \
  268.         1,                                            /* Array count */                \
  269.         {                                            /* It’s an array */                \
  270.             {                                        /* It’s a struct */                \
  271.                 (m68kProcInfo),                        /* the ProcInfo */                \
  272.                 0,                                    /* reserved */                    \
  273.                 kM68kISA |                            /* ISA */                        \
  274.                 kOld68kRTA,                            /* RTA */                        \
  275.                 kProcDescriptorIsAbsolute |            /* Flags - it’s absolute addr */\
  276.                 kUseCurrentISA,                        /* Use current ISA */            \
  277.                 (ProcPtr)(m68kProcPtr),                /* the procedure */                \
  278.                 0,                                    /* reserved */                    \
  279.                 0,                                    /* reserved */                    \
  280.             },                                                                        \
  281.             {                                        /* It’s a struct */                \
  282.                 (powerPCProcInfo),                    /* the ProcInfo */                \
  283.                 0,                                    /* reserved */                    \
  284.                 GetCurrentArchitecture(),             /* ISA and RTA */                \
  285.                 kProcDescriptorIsAbsolute |            /* Flags - it’s absolute addr */\
  286.                 kFragmentIsPrepared |                /* It’s prepared */                \
  287.                 kUseCurrentISA,                        /* Always use current ISA */    \
  288.                 (ProcPtr)(powerPCProcPtr),            /* the procedure */                \
  289.                 0,                                    /* reserved */                    \
  290.                 0                                    /* reserved */                    \
  291.             }                                                                        \
  292.         }                                                                            \
  293.     }
  294. /* Mixed Mode ProcInfos */
  295.  
  296. enum {
  297.                                                                 /* Calling Convention Offsets */
  298.     kCallingConventionWidth        = 4,
  299.     kCallingConventionPhase        = 0,
  300.     kCallingConventionMask        = 0x0F,                            /* Result Offsets */
  301.     kResultSizeWidth            = 2,
  302.     kResultSizePhase            = kCallingConventionWidth,
  303.     kResultSizeMask                = 0x30,                            /* Parameter offsets & widths */
  304.     kStackParameterWidth        = 2,
  305.     kStackParameterPhase        = (kCallingConventionWidth + kResultSizeWidth),
  306.     kStackParameterMask            = (long)0xFFFFFFC0,                /* Register Result Location offsets & widths */
  307.     kRegisterResultLocationWidth = 5,
  308.     kRegisterResultLocationPhase = (kCallingConventionWidth + kResultSizeWidth), /* Register Parameter offsets & widths */
  309.     kRegisterParameterWidth        = 5,
  310.     kRegisterParameterPhase        = (kCallingConventionWidth + kResultSizeWidth + kRegisterResultLocationWidth),
  311.     kRegisterParameterMask        = 0x7FFFF800,
  312.     kRegisterParameterSizePhase    = 0,
  313.     kRegisterParameterSizeWidth    = 2,
  314.     kRegisterParameterWhichPhase = kRegisterParameterSizeWidth,
  315.     kRegisterParameterWhichWidth = 3,                            /* Dispatched Stack Routine Selector offsets & widths */
  316.     kDispatchedSelectorSizeWidth = 2,
  317.     kDispatchedSelectorSizePhase = (kCallingConventionWidth + kResultSizeWidth), /* Dispatched Stack Routine Parameter offsets */
  318.     kDispatchedParameterPhase    = (kCallingConventionWidth + kResultSizeWidth + kDispatchedSelectorSizeWidth), /* Special Case offsets & widths */
  319.     kSpecialCaseSelectorWidth    = 6,
  320.     kSpecialCaseSelectorPhase    = kCallingConventionWidth,
  321.     kSpecialCaseSelectorMask    = 0x03F0
  322. };
  323.  
  324.  
  325. enum {
  326.     kSpecialCase                = 0x000F                        /* (CallingConventionType) */
  327. };
  328.  
  329.  
  330. enum {
  331.                                                                 /* all of the special cases enumerated.  The selector field is 6 bits wide */
  332.     kSpecialCaseHighHook        = 0,
  333.     kSpecialCaseCaretHook        = 0,                            /* same as kSpecialCaseHighHook */
  334.     kSpecialCaseEOLHook            = 1,
  335.     kSpecialCaseWidthHook        = 2,
  336.     kSpecialCaseTextWidthHook    = 2,                            /* same as kSpecialCaseWidthHook */
  337.     kSpecialCaseNWidthHook        = 3,
  338.     kSpecialCaseDrawHook        = 4,
  339.     kSpecialCaseHitTestHook        = 5,
  340.     kSpecialCaseTEFindWord        = 6,
  341.     kSpecialCaseProtocolHandler    = 7,
  342.     kSpecialCaseSocketListener    = 8,
  343.     kSpecialCaseTERecalc        = 9,
  344.     kSpecialCaseTEDoText        = 10,
  345.     kSpecialCaseGNEFilterProc    = 11,
  346.     kSpecialCaseMBarHook        = 12
  347. };
  348.  
  349.  
  350. /*
  351.     NOTES ON USING ROUTINE DESCRIPTOR FUNCTIONS
  352.     
  353.     When calling these routine from classic 68k code there are two possible intentions.
  354.  
  355.     The first is source compatibility with code ported to CFM (either PowerPC or 68k CFM). When
  356.     the code is compiled for CFM the functions create routine descriptors that can be used by
  357.     the mixed mode manager operating on that machine. When the code is compiled for classic 68k
  358.     these functions do nothing so that the code will run on Macintoshes that do not have a
  359.     mixed mode manager. The dual nature of these functions is achieved by turning the CFM calls
  360.     into "no-op" macros for classic 68k: You can put "NewRoutineDescriptor" in your source,
  361.     compile it for any runtime or instruction set architecture, and it will run correctly on the
  362.     intended runtime/instruction platform. All without source changes and/or conditional source.
  363.     
  364.     The other intention is for code that "knows" that it is executing as classic 68k runtime
  365.     and is specifically trying to call code of another architecture using mixed mode. Since the
  366.     routines were designed with classic <-> CFM source compatibility in mind this second case
  367.     is treated special. For classic 68k code to create routines descriptors for use by mixed mode
  368.     it must call the "Trap" versions of the routines (NewRoutineDescriptorTrap). These versions
  369.     are only available to classic 68k callers: rigging the interfaces to allow calling them
  370.     from CFM code will result in runtime failure because no shared library implements or exports
  371.     the functions.
  372.     
  373.  
  374.     This almost appears seamless until you consider "fat" routine descriptors and the advent of
  375.     CFM-68K. What does "fat" mean? CFM-68K is not emulated on PowerPC and PowerPC is not emulated
  376.     on CFM-68K. It makes no sense to create a routine descriptor having both a CFM-68K routine
  377.     and a PowerPC native routine pointer. Therefore "fat" is defined to be a mix of classic and
  378.     CFM for the hardware's native instruction set: on PowerPC fat is classic and PowerPC native,
  379.     on a 68k machine with CFM-68K installed fat is classic and CFM-68K.
  380.     
  381.     By definition fat routine descriptors are only constructed by code that is aware of the 
  382.     architecture it is executing as and that another architecture exists. Source compatibility
  383.     between code intented as pure classic and pure CFM is not an issue and so NewFatRoutineDescriptor
  384.     is not available when building pure classic code.
  385.     
  386.     NewFatRoutineDescriptorTrap is available to classic code on both PowerPC and CFM-68K. The
  387.     classic code can use the code fragment manager routine "FindSymbol" to obtain the address of 
  388.     a routine in a shared library and then construct a routine descriptor with both the CFM routine 
  389.     and classic    routine.
  390. */
  391.  
  392. #if TARGET_OS_MAC && TARGET_RT_MAC_CFM
  393. EXTERN_API( UniversalProcPtr )
  394. NewRoutineDescriptor            (ProcPtr                 theProc,
  395.                                  ProcInfoType             theProcInfo,
  396.                                  ISAType                 theISA);
  397.  
  398. EXTERN_API( void )
  399. DisposeRoutineDescriptor        (UniversalProcPtr         theProcPtr);
  400.  
  401. EXTERN_API( UniversalProcPtr )
  402. NewFatRoutineDescriptor            (ProcPtr                 theM68kProc,
  403.                                  ProcPtr                 thePowerPCProc,
  404.                                  ProcInfoType             theProcInfo);
  405.  
  406. #else
  407. #define DisposeRoutineDescriptor(theProcPtr)
  408. #define NewRoutineDescriptor(theProc, theProcInfo, theISA) ((UniversalProcPtr)theProc)
  409. /* Note that the call to NewFatRoutineDescriptor is undefined. */
  410. #endif  /* TARGET_OS_MAC && TARGET_RT_MAC_CFM */
  411.  
  412.  
  413. #if TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  414. /*
  415.     The "Trap" versions of the MixedMode calls are only for classic 68K clients that 
  416.     want to load and use CFM based code.
  417. */
  418. EXTERN_API( UniversalProcPtr )
  419. NewRoutineDescriptorTrap        (ProcPtr                 theProc,
  420.                                  ProcInfoType             theProcInfo,
  421.                                  ISAType                 theISA)                                TWOWORDINLINE(0x7000, 0xAA59);
  422.  
  423. EXTERN_API( void )
  424. DisposeRoutineDescriptorTrap    (UniversalProcPtr         theProcPtr)                            TWOWORDINLINE(0x7001, 0xAA59);
  425.  
  426. EXTERN_API( UniversalProcPtr )
  427. NewFatRoutineDescriptorTrap        (ProcPtr                 theM68kProc,
  428.                                  ProcPtr                 thePowerPCProc,
  429.                                  ProcInfoType             theProcInfo)                        TWOWORDINLINE(0x7002, 0xAA59);
  430.  
  431. #endif  /* TARGET_CPU_68K &&  !TARGET_RT_MAC_CFM */
  432.  
  433. #if TARGET_RT_MAC_CFM
  434. /*
  435.     CallUniversalProc is only implemented in shared libraries on CFM68K and PowerPC, it is now
  436.     conditionalize with TARGET_RT_MAC_CFM.  This will catch accidental calls from classic 68K code
  437.     that previously only showed up as linker errors.
  438. */
  439. EXTERN_API_C( long )
  440. CallUniversalProc                (UniversalProcPtr         theProcPtr,
  441.                                  ProcInfoType             procInfo,
  442.                                  ...);
  443.  
  444. EXTERN_API_C( long )
  445. CallOSTrapUniversalProc            (UniversalProcPtr         theProcPtr,
  446.                                  ProcInfoType             procInfo,
  447.                                  ...);
  448.  
  449. EXTERN_API_C( long )
  450. CallAsyncUniversalProc            (UniversalProcPtr         theProcPtr,
  451.                                  ProcInfoType             procInfo,
  452.                                  ...);
  453.  
  454. #endif  /* TARGET_RT_MAC_CFM */
  455.  
  456. #if TARGET_CPU_68K
  457. EXTERN_API( OSErr )
  458. SaveMixedModeState                (MixedModeStateRecord *    stateStorage,
  459.                                  UInt32                 stateVersion)                        TWOWORDINLINE(0x7003, 0xAA59);
  460.  
  461. EXTERN_API( OSErr )
  462. RestoreMixedModeState            (MixedModeStateRecord *    stateStorage,
  463.                                  UInt32                 stateVersion)                        TWOWORDINLINE(0x7004, 0xAA59);
  464.  
  465. #endif  /* TARGET_CPU_68K */
  466.  
  467. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
  468.  *
  469.  *    Macros for building ProcInfos.  Examples:
  470.  *    
  471.  *    
  472.  *    uppModalFilterProcInfo = kPascalStackBased
  473.  *         | RESULT_SIZE(SIZE_CODE(sizeof(Boolean)))
  474.  *         | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DialogPtr)))
  475.  *         | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(EventRecord*)))
  476.  *         | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(short*))),
  477.  *
  478.  *    uppDeskHookProcInfo = kRegisterBased
  479.  *         | REGISTER_ROUTINE_PARAMETER(1, kRegisterD0, SIZE_CODE(sizeof(Boolean)))
  480.  *         | REGISTER_ROUTINE_PARAMETER(2, kRegisterA0, SIZE_CODE(sizeof(EventRecord*)))
  481.  *
  482.  *    uppGXSpoolResourceProcInfo = kCStackBased
  483.  *         | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  484.  *         | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(gxSpoolFile)))
  485.  *         | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Handle)))
  486.  *         | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(ResType)))
  487.  *         | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(long)))
  488.  *
  489.  *    uppTEFindWordProcInfo = SPECIAL_CASE_PROCINFO( 6 ),
  490.  *
  491.  */
  492.  
  493.  
  494. /* * * * * * * * * * * * * * 
  495.  *    SIZE_CODE -     Return the size code for an object, given its size in bytes.
  496.  *        size - size of an object in bytes
  497.  */
  498. #define SIZE_CODE(size) \
  499.     (((size) == 4) ? kFourByteCode : (((size) == 2) ? kTwoByteCode : (((size) == 1) ? kOneByteCode : 0)))
  500.  
  501.  
  502. /* * * * * * * * * * * * * * 
  503.  *    RESULT_SIZE -     Return the result field of a ProcInfo, given the return object’s size.
  504.  *                     This is the same for all ProcInfos
  505.  *        sizeCode - size code
  506.  */
  507. #define RESULT_SIZE(sizeCode) \
  508.     ((ProcInfoType)(sizeCode) << kResultSizePhase)
  509.  
  510.  
  511. /* * * * * * * * * * * * * * 
  512.  *    STACK_ROUTINE_PARAMETER -    Return a parameter field of a ProcInfo, for a simple,
  513.  *                                non-dispatched, stack based routine.
  514.  *        whichParam - which parameter
  515.  *        sizeCode - size code
  516.  */
  517. #define STACK_ROUTINE_PARAMETER(whichParam, sizeCode) \
  518.     ((ProcInfoType)(sizeCode) << (kStackParameterPhase + (((whichParam) - 1) * kStackParameterWidth)))
  519.  
  520.  
  521. /* * * * * * * * * * * * * * 
  522.  *    DISPATCHED_STACK_ROUTINE_PARAMETER -    Return a parameter field of a ProcInfo, for 
  523.  *                                            a dispatched, stack based routine.  The same
  524.  *                                            macro is used regardless of the type of
  525.  *                                            dispatching.
  526.  *        whichParam - which parameter
  527.  *        sizeCode - size code
  528.  */
  529. #define DISPATCHED_STACK_ROUTINE_PARAMETER(whichParam, sizeCode) \
  530.     ((ProcInfoType)(sizeCode) << (kDispatchedParameterPhase + (((whichParam) - 1) * kStackParameterWidth)))
  531.  
  532.  
  533. /* * * * * * * * * * * * * * 
  534.  *    DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE -    Return a the selector size field of a ProcInfo
  535.  *                                                for a dispatched, stack based routine.  The
  536.  *                                                same macro is used regardless of the type of
  537.  *                                                dispatching.
  538.  *        sizeCode - size code 
  539.  */
  540. #define DISPATCHED_STACK_ROUTINE_SELECTOR_SIZE(sizeCode) \
  541.     ((ProcInfoType)(sizeCode) << kDispatchedSelectorSizePhase)
  542.  
  543.  
  544. /* * * * * * * * * * * * * * 
  545.  *    REGISTER_RESULT_LOCATION -        Return the Result Location field of a ProcInfo, 
  546.  *                                    given the location.
  547.  *        whichReg - which register
  548.  */
  549. #define REGISTER_RESULT_LOCATION(whichReg) \
  550.     ((ProcInfoType)(whichReg) << kRegisterResultLocationPhase)
  551.  
  552.  
  553. /* * * * * * * * * * * * * * 
  554.  *    REGISTER_ROUTINE_PARAMETER -    Return a parameter field of a ProcInfo for a 
  555.  *                                    register based routine.
  556.  */
  557. #define REGISTER_ROUTINE_PARAMETER(whichParam, whichReg, sizeCode) \
  558.     ((((ProcInfoType)(sizeCode) << kRegisterParameterSizePhase) | ((ProcInfoType)(whichReg) << kRegisterParameterWhichPhase)) << \
  559.             (kRegisterParameterPhase + (((whichParam) - 1) * kRegisterParameterWidth)))
  560.  
  561.  
  562. /* * * * * * * * * * * * * * 
  563.  *
  564.  *    SPECIAL_CASE_PROCINFO -     Returns the procInfo constant for the following special cases:
  565.  *    
  566.  *        High Hook & Caret Hook -  (see I-379)
  567.  *            C calling conventions, Rect on stack, pointer in A3, no return value
  568.  *        EOL Hook - (see VI-15-26)
  569.  *            Register-based; inputs in D0, A3, A4; 
  570.  *            output is Z flag of status register
  571.  *        Width Hook - (see VI-15-27)
  572.  *            Register-based; inputs in D0, D1, A0, A3, A4; output in D1 
  573.  *        NWidth Hook - (see VI-15-27)
  574.  *            Register-based; inputs in D0, D1, D2, A0, A2, A3, A4; output in D1 
  575.  *        TextWidthHook - (see VI-15-28)
  576.  *            Register-based; inputs in D0, D1, A0, A3, A4; output in D1 
  577.  *        DrawHook - (see VI-15-28)
  578.  *            Register-based; inputs in D0, D1, A0, A3, A4; no output
  579.  *        HitTestHook - (See VI-15-29)
  580.  *            Register-based; inputs in D0, D1, D2, A0, A3, A4; outputs in D0, D1, D2
  581.  *        FindWord -  (see VI-15-30)
  582.  *            Register-based; inputs in D0, D2, A3, A4; outputs in D0, D1
  583.  *        ADBRoutines - (see V-371)
  584.  *            Register-based; inputs in A0, A1, A2, D0; no outputs
  585.  *        ProtocolHandler - (see II-326)
  586.  *            Register-based; inputs in A0, A1, A2, A3, A4, D1.w; output in Z 
  587.  *        SocketListener - (see II-329)
  588.  *            Register-based; inputs in A0, A1, A2, A3, A4, D0.b, D1.w; output in Z 
  589.  *        Reclac - (see I-391)
  590.  *            Register-based; inputs in A3, D7; outputs in D2, D3, D4
  591.  *        DoText - (see I-391)
  592.  *            Register-based; inputs in A3, D3, D4, D7; outputs in A0, D0
  593.  *        GNEFilterProc - (see tech note 85)
  594.  *            Register & Stack Based; inputs in A1, D0 & on the stack; outputs on the stack
  595.  *        MenuBarHook - (see I-356)
  596.  *            Register & Stack Based; input on the stack; output in D0
  597. */
  598. #define SPECIAL_CASE_PROCINFO(specialCaseCode)            \
  599.         (kSpecialCase | ((ProcInfoType)(specialCaseCode) << 4))
  600.  
  601.  
  602. /* * * * * * * * * * * * * * * 
  603.  *    STACK_UPP_TYPE    - used in typedefs to create ≈UPP type
  604.  *    REGISTER_UPP_TYPE - used in typedefs to create ≈UPP type
  605.  *
  606.  *    Example:
  607.  *
  608.  *        typedef STACK_UPP_TYPE(ModalFilterProcPtr)         ModalFilterUPP;
  609.  *        typedef REGISTER_UPP_TYPE(IOCompletionProcPtr)     IOCompletionUPP;
  610.  *
  611.  */
  612. #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  613.     /* classic 68k runtime */
  614.     #define STACK_UPP_TYPE(name)     name
  615.     #define REGISTER_UPP_TYPE(name) Register68kProcPtr
  616. #elif TARGET_OS_MAC && TARGET_RT_MAC_CFM
  617.     /* PowerPC and CFM68K runtime */
  618.     #define STACK_UPP_TYPE(name)     UniversalProcPtr
  619.     #define REGISTER_UPP_TYPE(name) UniversalProcPtr
  620. #else
  621.     /* other runtimes */
  622.     #define STACK_UPP_TYPE(name)     name
  623.     #define REGISTER_UPP_TYPE(name) name
  624. #endif
  625.  
  626.  
  627. /* * * * * * * * * * * * * * * 
  628.  *    CALL_≈_PARAMETER_UPP  - used in Call≈Proc macros
  629.  *
  630.  *    Example:
  631.  *
  632.  *        #define CallIOCompletionProc(userRoutine, paramBlock)     \
  633.  *                CALL_TWO_PARAMETER_UPP((userRoutine), uppIOCompletionProcInfo, (paramBlock))
  634.  *
  635.  */
  636. #if TARGET_OS_MAC && TARGET_RT_MAC_CFM
  637.     #define CALL_ZERO_PARAMETER_UPP(    upp, procInfo)         CallUniversalProc(upp, procInfo)
  638.     #define CALL_ONE_PARAMETER_UPP(     upp, procInfo, p1)         CallUniversalProc(upp, procInfo, (p1))
  639.     #define CALL_TWO_PARAMETER_UPP(     upp, procInfo, p1, p2)         CallUniversalProc(upp, procInfo, (p1), (p2))
  640.     #define CALL_THREE_PARAMETER_UPP(   upp, procInfo, p1, p2, p3)         CallUniversalProc(upp, procInfo, (p1), (p2), (p3))
  641.     #define CALL_FOUR_PARAMETER_UPP(    upp, procInfo, p1, p2, p3, p4)         CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4))
  642.     #define CALL_FIVE_PARAMETER_UPP(    upp, procInfo, p1, p2, p3, p4, p5)         CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5))
  643.     #define CALL_SIX_PARAMETER_UPP(     upp, procInfo, p1, p2, p3, p4, p5, p6)         CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5), (p6))
  644.     #define CALL_SEVEN_PARAMETER_UPP(   upp, procInfo, p1, p2, p3, p4, p5, p6, p7)         CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7))
  645.     #define CALL_EIGHT_PARAMETER_UPP(   upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8)         CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8))
  646.     #define CALL_NINE_PARAMETER_UPP(    upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9)         CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9))
  647.     #define CALL_TEN_PARAMETER_UPP(     upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10)     CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9), (p10))
  648.     #define CALL_ELEVEN_PARAMETER_UPP(  upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11)     CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9), (p10), (p11))
  649.     #define CALL_TWELVE_PARAMETER_UPP(  upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12)    CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9), (p10), (p11), (p12))
  650.     #define CALL_THIRTEEN_PARAMETER_UPP(upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13)    CallUniversalProc(upp, procInfo, (p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9), (p10), (p11), (p12), (p13))
  651. #else
  652.     #define CALL_ZERO_PARAMETER_UPP(    upp, procInfo)         (*(upp))()
  653.     #define CALL_ONE_PARAMETER_UPP(     upp, procInfo, p1)         (*(upp))((p1))
  654.     #define CALL_TWO_PARAMETER_UPP(     upp, procInfo, p1, p2)         (*(upp))((p1), (p2))
  655.     #define CALL_THREE_PARAMETER_UPP(   upp, procInfo, p1, p2, p3)         (*(upp))((p1), (p2), (p3))
  656.     #define CALL_FOUR_PARAMETER_UPP(    upp, procInfo, p1, p2, p3, p4)         (*(upp))((p1), (p2), (p3), (p4))
  657.     #define CALL_FIVE_PARAMETER_UPP(    upp, procInfo, p1, p2, p3, p4, p5)         (*(upp))((p1), (p2), (p3), (p4), (p5))
  658.     #define CALL_SIX_PARAMETER_UPP(     upp, procInfo, p1, p2, p3, p4, p5, p6)         (*(upp))((p1), (p2), (p3), (p4), (p5), (p6))
  659.     #define CALL_SEVEN_PARAMETER_UPP(   upp, procInfo, p1, p2, p3, p4, p5, p6, p7)         (*(upp))((p1), (p2), (p3), (p4), (p5), (p6), (p7))
  660.     #define CALL_EIGHT_PARAMETER_UPP(   upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8)         (*(upp))((p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8))
  661.     #define CALL_NINE_PARAMETER_UPP(    upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9)         (*(upp))((p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9))
  662.     #define CALL_TEN_PARAMETER_UPP(     upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10)     (*(upp))((p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9), (p10))
  663.     #define CALL_ELEVEN_PARAMETER_UPP(  upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11)     (*(upp))((p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9), (p10), (p11))
  664.     #define CALL_TWELVE_PARAMETER_UPP(  upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12)     (*(upp))((p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9), (p10), (p11), (p12))
  665.     #define CALL_THIRTEEN_PARAMETER_UPP(upp, procInfo, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13)     (*(upp))((p1), (p2), (p3), (p4), (p5), (p6), (p7), (p8), (p9), (p10), (p11), (p12), (p13))
  666. #endif
  667.  
  668.  
  669.  
  670.  
  671.  
  672. #if PRAGMA_STRUCT_ALIGN
  673.     #pragma options align=reset
  674. #elif PRAGMA_STRUCT_PACKPUSH
  675.     #pragma pack(pop)
  676. #elif PRAGMA_STRUCT_PACK
  677.     #pragma pack()
  678. #endif
  679.  
  680. #ifdef PRAGMA_IMPORT_OFF
  681. #pragma import off
  682. #elif PRAGMA_IMPORT
  683. #pragma import reset
  684. #endif
  685.  
  686. #ifdef __cplusplus
  687. }
  688. #endif
  689.  
  690. #endif /* __MIXEDMODE__ */
  691.  
  692.